//
//  MyWalletController.m
//  WuJieLive
//
//  Created by 张瀚坤 on 2017/10/30.
//  Copyright © 2017年 zhk. All rights reserved.
//

#import "MyWalletController.h"
#import "RechargeController.h"
#import "AllDetailController.h"
#import "IncomeDetailController.h"
#import "PayDetailController.h"
#import "MyCardController.h"
#import "GetMoneyController.h"

@interface MyWalletController ()
@property (weak, nonatomic) IBOutlet UIButton *RechargeBtn;
@property (weak, nonatomic) IBOutlet UIButton *getMoneyBtn;
@property (weak, nonatomic) IBOutlet UIButton *cardBtn;
@property (weak, nonatomic) IBOutlet UIView *btnView;
@property (weak, nonatomic) IBOutlet UIButton *cardNumBtn;
@property (weak, nonatomic) IBOutlet UILabel *moneyLabel;

@property (nonatomic, strong) UIView *contentView;
@property (nonatomic , strong) AllDetailController * allVC;
@property (nonatomic , strong) IncomeDetailController * incomeVC;
@property (nonatomic , strong) PayDetailController * payVC;
@property (nonatomic, strong)UIViewController *currentVC;

@end

@implementation MyWalletController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

-(void)setNavi
{
    self.title = @"我的钱包";
    [self.rightBtn setImage:Image(@"icon_nav_说明") forState:(UIControlStateNormal)];
}

-(void)setUI
{
    self.view.backgroundColor = Color(245, 245, 245);
    self.RechargeBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    self.getMoneyBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    self.cardBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    self.cardNumBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -80);
    
    self.currentVC = self.allVC;
    
    SegementScrollView * view = [[SegementScrollView alloc]initWithFrame:CGRectMake(0, 180, kScreenWidth, 40) andtitleArray:@[@"全部",@"收入",@"支出"]];
    [self.view addSubview:view];
    view.selectedBlock = ^(NSInteger index) {
        if (index == 0) {
            [self changeControllerFromOldController:self.currentVC toNewController:self.allVC];
        }else if (index == 1)
        {
            [self changeControllerFromOldController:self.currentVC toNewController:self.incomeVC];
        }else
        {
            [self changeControllerFromOldController:self.currentVC toNewController:self.payVC];
        }
    };
    [self loadChildController];
}

- (void)loadChildController
{
    self.contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 220, kScreenWidth, kScreenHeight - 220 - 50 - 64)];
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.contentView];
    
    self.allVC = [AllDetailController new];
    [self.allVC.view setFrame:_contentView.bounds];
    [self addChildViewController:self.allVC];
    
    self.incomeVC = [IncomeDetailController new];
    [self.incomeVC.view setFrame:_contentView.bounds];
    
    self.payVC = [PayDetailController new];
    [self.payVC.view setFrame:_contentView.bounds];
    
    [self.contentView addSubview:self.allVC.view];
    self.currentVC = self.allVC;
}

-(void)setData
{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSDictionary * dict = @{@"token":self.userToken};
    [HTTPTool POSTForm:[NSString stringWithFormat:@"%@deposit-account/my-wallet",BaseUrl] para:dict success:^(BOOL isSuccess, id responseObject) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (isSuccess) {
            self.moneyLabel.text = self.accountMoney = [responseObject objectForKey:@"data"][@"money"];
            [self.cardNumBtn setTitle:[responseObject objectForKey:@"data"][@"bank_count"]  forState:(UIControlStateNormal)];
        }
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}

#pragma mark - 切换viewController
- (void)changeControllerFromOldController:(UIViewController *)oldController toNewController:(UIViewController *)newController {
    [self addChildViewController:newController];
    [self transitionFromViewController:oldController toViewController:newController duration:0.3 options:UIViewAnimationOptionCurveEaseIn animations:^{
        
    } completion:^(BOOL finished) {
        if (finished) {
            [newController didMoveToParentViewController:self];
            [oldController willMoveToParentViewController:nil];
            [oldController removeFromParentViewController];
            _currentVC = newController;
        } else {
            _currentVC = oldController;
        }
    }];
}

#pragma mark 充值
- (IBAction)rechargeAction:(id)sender {
    RechargeController * vc = [[RechargeController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark 提现
- (IBAction)getMoneyAction:(id)sender {
    GetMoneyController * vc = [[GetMoneyController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark 说明
-(void)rightBtnAction:(UIButton *)sender
{
    
}

#pragma mark
- (IBAction)toCardAction:(id)sender {
    MyCardController * vc = [[MyCardController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark
- (IBAction)toCartVCAction:(id)sender {
    MyCardController * vc = [[MyCardController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
